module ApplicationHelper
#  require "fusioncharts_helper"
#  include FusionChartsHelper
#
#  def im_here?(str_ctr_name,act_name,list_str_name,list_act_name)
#    if (list_str_name.include?(str_ctr_name)) and (list_act_name.include?(act_name))
#      concat("here")
#    else
#      concat("")
#    end
#  end

  def title(title) #Titulo de la Pagina
    content_for(:title) {title}
  end

  def javascript(*files) #Jalar JS al HEAD
    content_for(:head) {javascript_include_tag(*files)}
  end

  def stylesheet(*files) #Jalar CSS al HEAD
    content_for(:head) {stylesheet_link_tag(*files)}
  end

  def calendar_date_select_style(*files) #JALAR Calendar
    content_for(:head) {calendar_date_select_includes(*files)}
  end

  def jquery_validationengine(form_id) #Ejecutar el Validador, recibe el ID del Form a Validar
    concat("\n<script type='text/javascript'>\n")
    concat("\t$jq = jQuery.noConflict();\n")
    concat("\t$jq(document).ready(function() {\n")
    concat("\t$jq('##{form_id}').validationEngine();\n")
    concat("\t})\n")
    concat("</script>")
  end

  def translation_calendar #Traduccion del calendario a español
    concat("\n<script type='text/javascript'>\n")
    concat("\t_translations = {\n")
    concat("\t\t"+'"OK": "OK",'+"\n")
    concat("\t\t"+'"Now": "Ahora",'+"\n")
    concat("\t\t"+'"Today": "Hoy",'+"\n")
    concat("\t\t"+'"Clear": "Limpiar"'+"\n")
    concat("\t}\n")
    concat("\t"+'Date.weekdays = $w("D L Ma Mi J V S");'+"\n")
    concat("</script>")
  end

  def flash_messages
    if !flash[:notice].blank?
      concat('<ul class="system_messages">')
      concat("\t"+'<li class="'+flash[:type_message].to_s+'">')
      concat("\t\t"+'<span class="ico"></span>')
      concat("\t\t"+'<strong class="system_title">'+flash[:notice].to_s+'</strong>')
      concat("\t"+'</li>')
      concat("</ul>")
    end
  end

  def mail(str_mail)
    return '<a href="mailto:'+str_mail+'">'+str_mail+'</a>'
  end

  def get_str_order(column,order,init='ASC')
    if order.include?(column)
      if order.include?("ASC")
        return "#{column} DESC"
      else
        return "#{column} ASC"
      end
    else
      return "#{column} #{init}"
    end
  end

  def get_str_order_title(str_order,name)
    if str_order.include?("ASC")
      return "Ordenar por #{name} Ascendentemente"
    else
      return "Ordenar por #{name} Descendentemente"
    end
  end

  def set_label_obligatory(nullable)
    return (nullable)? "":"<span style=\"color:red\">(*) </span>"
  end

  def set_validate(nullable)
    return (nullable)? "optional":"required"
  end

  def litle_url(large_url)
    require "rubygems"
    require "bitly"
        Bitly.use_api_version_3
        service = Bitly.new('shintta','R_ee3152419b933c10bc5ae686768b0db5')
        litle_url_return = service.shorten(large_url)        
        if litle_url_return.blank?
          return nil
        else         
          return litle_url_return.short_url
        end
  end
end
